<?php

/**
 * class CompanyView
 *  
 */
class CompanyView extends View {

    
    public function __call($name, $arguments) {
       echo "вызвали ".$name."<br>";
    }
    
    
    public static function getSearchForm($data) {
        return '
<div class="span6">
<form method="GET" class="well form-inline">
    <label><input type="text" name="name" placeholder="Название организации"></label>
    <label><select name="address" class="input-small"><option value="USA">USA</option></select></label>
    <input type="submit" value="Фильтр" name="filter_submit" class="btn"> 
</form>
</div>';
    }

    public static function getTableWithCompanies($companies) {

        $out='';
        $out.='<div class="span6"><table class="table">';
        $out.='<tr><th>Название организации</th><th>Адрес</th><th>Сфера деятельности</th></tr>';
        if (!empty($companies))
            foreach ($companies as $company) {
                $out.='<tr><td><a href="' . HTTP_SERVER . 'Company/profile/'.$company['company_id'].'">' . $company['name'] . '</a></td><td>' . $company['address'] . '</td><td>' . $company['sphere'] . '</td></tr>';
            }
        else
            $out.='<tr><td colspan="3" align="center">Пусто</td></tr>';
        $out.='</table></div>';
        
        return $out;
    }
    

    public static function getCompanyCreationForm($data, $mode) {
        return '
<div class="span6">
    <form class="form-horizontal" method="post" action="' . HTTP_SERVER . ($mode == 'edit' ? 'Company/edit/' . $data['company_id'] : 'Company/create') . '">
                <fieldset>
                    <div class="control-group">
                        <label class="control-label">Название компании:</label><div class="controls"><input type="text" name="name" class="span3" value="' . @$data['name'] . '"></div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">Адрес:</label><div class="controls"><input type="text" name="address" class="span3" value="' . @$data['address'] . '"></div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">Сфера деятельности:</label><div class="controls"><select name="sphere" class="span3"><option value="0">Нефтяная</option></select></div>
                    </div>
                    <div class="form-actions">
                        <input name="submit" type="submit" value="' . ($mode == 'edit' ? 'Сохранить изменения' : 'Создать компанию') . '" class="btn btn-primary"> 
                    </div>
                </fieldset>
            </form>
</div>';
    }

    public static function getCompanyProfile($data, $isOwner) {
        $out='';
        $out.='<div class="span6">';
        if ($isOwner)
        {
            $out.='<small>Ваша компания</small>';
            $out.='<div class="edit_button"><a href="' . HTTP_SERVER . 'Company/edit/' . $data['company_id'] . '" class="btn btn-primary">ред.</a></div>';
        }

        $out.='<h3>' . $data['name'] . '</h3>
            <table class="table">
                <tr><td>Владелец компании:</td><td>' . $data['owner']['realname'] . ' [<a href="#">' . $data['owner']['user_login'] . '</a>]</td></tr>
                <tr><td>Адрес:</td><td>' . $data['address'] . '</td></tr>
                <tr><td>Сфера деятельности:</td><td>' . $data['sphere'] . '</td></tr>
            </table>
</div>';
        return $out;
    }

}

?>